package com.prelearning.at_springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.prelearning.at_springboot.entity.Published;
import com.prelearning.at_springboot.service.IPublishedService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.prelearning.at_springboot.service.IUnpublishService;
import com.prelearning.at_springboot.entity.Unpublish;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cgr
 * @since 2022-04-10
 */
@RestController
@RequestMapping("/unpublish")
public class UnpublishController {

    @Resource
    private IUnpublishService unpublishService;

    //定时器定时清洗数据库
    @Scheduled(cron = "*/6 * * * * ?")
    private void process() {
        unpublishService.refresh();
    }

    // 新增或者更新
    @PostMapping
    public boolean save(@RequestBody Unpublish unpublish) {
        return unpublishService.saveOrUpdate(unpublishService.init(unpublish));
    }

    //根据签到表单id删除签到
    @DeleteMapping("/del/{id}")
    public Boolean delete(@PathVariable String id) {
            return unpublishService.removeById(id);
    }

    //多项删除
    @PostMapping("/del/batch")
    public boolean deleteBatch(@RequestBody List<String> ids) {
            return unpublishService.removeByIds(ids);
    }

    //根据群主id获取未完成签到
    @GetMapping("/all/{owner_id}")
    public List<Unpublish> findPublished(@PathVariable String owner_id) { return unpublishService.getUnpublish(owner_id); }

    //获取所有未发布签到
    @GetMapping
    public List<Unpublish> findAll() {
            return unpublishService.list(new QueryWrapper<Unpublish>().orderByDesc("creat_time"));
    }

    //根据签到表id获取unpublish对象
    @GetMapping("/{id}")
    public Unpublish findOne(@PathVariable String id) {
            return unpublishService.getById(id);
    }



}

